export default {
    // 添加切片的命名空间
    namespaced:'goods',
    state:{
        goodsList:[
            {
                id:1,
                gname:'华为',
                price:2000
            }
        ]
    },
    getters:{
        totalNum(state){
            return state.goodsList.length;
        }
    },
    actions:{
        addGoods(context, goods){ // {gname:'', price:2000}
            context.commit('ADD_GOODS',{
                id:Math.random().toString(36).slice(2),
                ...goods
            })
        }
    },
    mutations:{
        ADD_GOODS(state, goods){
            state.goodsList.push(goods)
        }
    }
}